package com.kclm.xsap.utils.time;

import com.kclm.xsap.entity.TimeEntity;

import java.time.LocalTime;
import java.util.List;

public class JudgeTimeUtils {

    public static boolean judgeTime(List<TimeEntity> timeEntities, TimeEntity testTimeEntity) {

        if (timeEntities.isEmpty()) {
            return true;
        }

        boolean isOverlap = true;

        for (TimeEntity timeEntity : timeEntities) {
            isOverlap = isOverlap(testTimeEntity, timeEntity);
            if(!isOverlap) {
                break;
            }
        }

        return isOverlap;
    }

    public static boolean isOverlap(TimeEntity testTimeEntity, TimeEntity timeEntity) {
        LocalTime st = testTimeEntity.getStartTime();
        LocalTime se = testTimeEntity.getEndTime();
        //待排课程的开始时间比已有课程的开始时间要大, 且比已有课程的结束时间要大
        if(st.isAfter(timeEntity.getStartTime()) && st.isAfter(timeEntity.getEndTime())) {
            return true;
            //待排课程的结束时间比已有课程的开始时间要小, 且比已有课程的开始时间要小
        } else if(st.isBefore(timeEntity.getStartTime()) && se.isBefore(timeEntity.getStartTime())) {
            return true;
        }
        return false;
    }
}
